<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>
        显示密码
    </button>
    <input type="password">
    <script>
        var btn = document.querySelector('button');
        var input = document.querySelector('input');
        var flag;
        btn.onclick = function () {
            if (flag) {
                input.type = 'password';
                flag = false;
            } else {
                input.type = 'text';
                flag = true;
            }
        }
    </script>
</body>

</html>